﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;
using System.Xml.Serialization;

namespace super_scrable.Models
{
    public class Matrix
    {
        public static String pathfile = @"matrix.xml";

        private List<Case> grid = new List<Case>();

        public Matrix()
        {
            initGrid();
        }

        private void initGrid()
        {
            grid.Add(new Case(1, 'A', Case.ROUGE));
            grid.Add(new Case(2, 'A', Case.BLANC));
            grid.Add(new Case(3, 'A', Case.BLANC));
            grid.Add(new Case(4, 'A', Case.BLEU_CLAIR));
            grid.Add(new Case(5, 'A', Case.BLANC));
            grid.Add(new Case(6, 'A', Case.BLANC));
            grid.Add(new Case(7, 'A', Case.BLANC));
            grid.Add(new Case(8, 'A', Case.ROUGE));
            grid.Add(new Case(9, 'A', Case.BLANC));
            grid.Add(new Case(10, 'A', Case.BLANC));
            grid.Add(new Case(11, 'A', Case.BLANC));
            grid.Add(new Case(12, 'A', Case.BLEU_CLAIR));
            grid.Add(new Case(13, 'A', Case.BLANC));
            grid.Add(new Case(14, 'A', Case.BLANC));
            grid.Add(new Case(15, 'A', Case.ROUGE));

            grid.Add(new Case(1, 'B', Case.BLANC));
            grid.Add(new Case(2, 'B', Case.ROSE));
            grid.Add(new Case(3, 'B', Case.BLANC));
            grid.Add(new Case(4, 'B', Case.BLANC));
            grid.Add(new Case(5, 'B', Case.BLANC));
            grid.Add(new Case(6, 'B', Case.BLEU_FONCE));
            grid.Add(new Case(7, 'B', Case.BLANC));
            grid.Add(new Case(8, 'B', Case.BLANC));
            grid.Add(new Case(9, 'B', Case.BLANC));
            grid.Add(new Case(10, 'B', Case.BLEU_FONCE));
            grid.Add(new Case(11, 'B', Case.BLANC));
            grid.Add(new Case(12, 'B', Case.BLANC));
            grid.Add(new Case(13, 'B', Case.BLANC));
            grid.Add(new Case(14, 'B', Case.ROSE));
            grid.Add(new Case(15, 'B', Case.BLANC));

            grid.Add(new Case(1, 'C', Case.BLANC));
            grid.Add(new Case(2, 'C', Case.BLANC));
            grid.Add(new Case(3, 'C', Case.ROSE));
            grid.Add(new Case(4, 'C', Case.BLANC));
            grid.Add(new Case(5, 'C', Case.BLANC));
            grid.Add(new Case(6, 'C', Case.BLANC));
            grid.Add(new Case(7, 'C', Case.BLEU_CLAIR));
            grid.Add(new Case(8, 'C', Case.BLANC));
            grid.Add(new Case(9, 'C', Case.BLEU_CLAIR));
            grid.Add(new Case(10, 'C', Case.BLANC));
            grid.Add(new Case(11, 'C', Case.BLANC));
            grid.Add(new Case(12, 'C', Case.BLANC));
            grid.Add(new Case(13, 'C', Case.ROSE));
            grid.Add(new Case(14, 'C', Case.BLANC));
            grid.Add(new Case(15, 'C', Case.BLANC));

            grid.Add(new Case(1, 'D', Case.BLEU_CLAIR));
            grid.Add(new Case(2, 'D', Case.BLANC));
            grid.Add(new Case(3, 'D', Case.BLANC));
            grid.Add(new Case(4, 'D', Case.ROSE));
            grid.Add(new Case(5, 'D', Case.BLANC));
            grid.Add(new Case(6, 'D', Case.BLANC));
            grid.Add(new Case(7, 'D', Case.BLANC));
            grid.Add(new Case(8, 'D', Case.BLEU_CLAIR));
            grid.Add(new Case(9, 'D', Case.BLANC));
            grid.Add(new Case(10, 'D', Case.BLANC));
            grid.Add(new Case(11, 'D', Case.BLANC));
            grid.Add(new Case(12, 'D', Case.ROSE));
            grid.Add(new Case(13, 'D', Case.BLANC));
            grid.Add(new Case(14, 'D', Case.BLANC));
            grid.Add(new Case(15, 'D', Case.BLEU_CLAIR));

            grid.Add(new Case(1, 'E', Case.BLANC));
            grid.Add(new Case(2, 'E', Case.BLANC));
            grid.Add(new Case(3, 'E', Case.BLANC));
            grid.Add(new Case(4, 'E', Case.BLANC));
            grid.Add(new Case(5, 'E', Case.ROSE));
            grid.Add(new Case(6, 'E', Case.BLANC));
            grid.Add(new Case(7, 'E', Case.BLANC));
            grid.Add(new Case(8, 'E', Case.BLANC));
            grid.Add(new Case(9, 'E', Case.BLANC));
            grid.Add(new Case(10, 'E', Case.BLANC));
            grid.Add(new Case(11, 'E', Case.ROSE));
            grid.Add(new Case(12, 'E', Case.BLANC));
            grid.Add(new Case(13, 'E', Case.BLANC));
            grid.Add(new Case(14, 'E', Case.BLANC));
            grid.Add(new Case(15, 'E', Case.BLANC));

            grid.Add(new Case(1, 'F', Case.BLANC));
            grid.Add(new Case(2, 'F', Case.BLEU_FONCE));
            grid.Add(new Case(3, 'F', Case.BLANC));
            grid.Add(new Case(4, 'F', Case.BLANC));
            grid.Add(new Case(5, 'F', Case.BLANC));
            grid.Add(new Case(6, 'F', Case.BLEU_FONCE));
            grid.Add(new Case(7, 'F', Case.BLANC));
            grid.Add(new Case(8, 'F', Case.BLANC));
            grid.Add(new Case(9, 'F', Case.BLANC));
            grid.Add(new Case(10, 'F', Case.BLEU_FONCE));
            grid.Add(new Case(11, 'F', Case.BLANC));
            grid.Add(new Case(12, 'F', Case.BLANC));
            grid.Add(new Case(13, 'F', Case.BLANC));
            grid.Add(new Case(14, 'F', Case.BLEU_FONCE));
            grid.Add(new Case(15, 'F', Case.BLANC));

            grid.Add(new Case(1, 'G', Case.BLANC));
            grid.Add(new Case(2, 'G', Case.BLANC));
            grid.Add(new Case(3, 'G', Case.BLEU_CLAIR));
            grid.Add(new Case(4, 'G', Case.BLANC));
            grid.Add(new Case(5, 'G', Case.BLANC));
            grid.Add(new Case(6, 'G', Case.BLANC));
            grid.Add(new Case(7, 'G', Case.BLEU_CLAIR));
            grid.Add(new Case(8, 'G', Case.BLANC));
            grid.Add(new Case(9, 'G', Case.BLEU_CLAIR));
            grid.Add(new Case(10, 'G', Case.BLANC));
            grid.Add(new Case(11, 'G', Case.BLANC));
            grid.Add(new Case(12, 'G', Case.BLANC));
            grid.Add(new Case(13, 'G', Case.BLEU_CLAIR));
            grid.Add(new Case(14, 'G', Case.BLANC));
            grid.Add(new Case(15, 'G', Case.BLANC));

            grid.Add(new Case(1, 'H', Case.ROUGE));
            grid.Add(new Case(2, 'H', Case.BLANC));
            grid.Add(new Case(3, 'H', Case.BLANC));
            grid.Add(new Case(4, 'H', Case.BLEU_CLAIR));
            grid.Add(new Case(5, 'H', Case.BLANC));
            grid.Add(new Case(6, 'H', Case.BLANC));
            grid.Add(new Case(7, 'H', Case.BLANC));
            grid.Add(new Case(8, 'H', Case.ROSE));
            grid.Add(new Case(9, 'H', Case.BLANC));
            grid.Add(new Case(10, 'H', Case.BLANC));
            grid.Add(new Case(11, 'H', Case.BLANC));
            grid.Add(new Case(12, 'H', Case.BLEU_CLAIR));
            grid.Add(new Case(13, 'H', Case.BLANC));
            grid.Add(new Case(14, 'H', Case.BLANC));
            grid.Add(new Case(15, 'H', Case.ROUGE));

            grid.Add(new Case(1, 'I', Case.BLANC));
            grid.Add(new Case(2, 'I', Case.BLANC));
            grid.Add(new Case(3, 'I', Case.BLEU_CLAIR));
            grid.Add(new Case(4, 'I', Case.BLANC));
            grid.Add(new Case(5, 'I', Case.BLANC));
            grid.Add(new Case(6, 'I', Case.BLANC));
            grid.Add(new Case(7, 'I', Case.BLEU_CLAIR));
            grid.Add(new Case(8, 'I', Case.BLANC));
            grid.Add(new Case(9, 'I', Case.BLEU_CLAIR));
            grid.Add(new Case(10, 'I', Case.BLANC));
            grid.Add(new Case(11, 'I', Case.BLANC));
            grid.Add(new Case(12, 'I', Case.BLANC));
            grid.Add(new Case(13, 'I', Case.BLEU_CLAIR));
            grid.Add(new Case(14, 'I', Case.BLANC));
            grid.Add(new Case(15, 'I', Case.BLANC));

            grid.Add(new Case(1, 'J', Case.BLANC));
            grid.Add(new Case(2, 'J', Case.BLEU_FONCE));
            grid.Add(new Case(3, 'J', Case.BLANC));
            grid.Add(new Case(4, 'J', Case.BLANC));
            grid.Add(new Case(5, 'J', Case.BLANC));
            grid.Add(new Case(6, 'J', Case.BLEU_FONCE));
            grid.Add(new Case(7, 'J', Case.BLANC));
            grid.Add(new Case(8, 'J', Case.BLANC));
            grid.Add(new Case(9, 'J', Case.BLANC));
            grid.Add(new Case(10, 'J', Case.BLEU_FONCE));
            grid.Add(new Case(11, 'J', Case.BLANC));
            grid.Add(new Case(12, 'J', Case.BLANC));
            grid.Add(new Case(13, 'J', Case.BLANC));
            grid.Add(new Case(14, 'J', Case.BLEU_FONCE));
            grid.Add(new Case(15, 'J', Case.BLANC));

            grid.Add(new Case(1, 'K', Case.BLANC));
            grid.Add(new Case(2, 'K', Case.BLANC));
            grid.Add(new Case(3, 'K', Case.BLANC));
            grid.Add(new Case(4, 'K', Case.BLANC));
            grid.Add(new Case(5, 'K', Case.ROSE));
            grid.Add(new Case(6, 'K', Case.BLANC));
            grid.Add(new Case(7, 'K', Case.BLANC));
            grid.Add(new Case(8, 'K', Case.BLANC));
            grid.Add(new Case(9, 'K', Case.BLANC));
            grid.Add(new Case(10, 'K', Case.BLANC));
            grid.Add(new Case(11, 'K', Case.ROSE));
            grid.Add(new Case(12, 'K', Case.BLANC));
            grid.Add(new Case(13, 'K', Case.BLANC));
            grid.Add(new Case(14, 'K', Case.BLANC));
            grid.Add(new Case(15, 'K', Case.BLANC));

            grid.Add(new Case(1, 'L', Case.BLEU_CLAIR));
            grid.Add(new Case(2, 'L', Case.BLANC));
            grid.Add(new Case(3, 'L', Case.BLANC));
            grid.Add(new Case(4, 'L', Case.ROSE));
            grid.Add(new Case(5, 'L', Case.BLANC));
            grid.Add(new Case(6, 'L', Case.BLANC));
            grid.Add(new Case(7, 'L', Case.BLANC));
            grid.Add(new Case(8, 'L', Case.BLEU_CLAIR));
            grid.Add(new Case(9, 'L', Case.BLANC));
            grid.Add(new Case(10, 'L', Case.BLANC));
            grid.Add(new Case(11, 'L', Case.BLANC));
            grid.Add(new Case(12, 'L', Case.ROSE));
            grid.Add(new Case(13, 'L', Case.BLANC));
            grid.Add(new Case(14, 'L', Case.BLANC));
            grid.Add(new Case(15, 'L', Case.BLEU_CLAIR));

            grid.Add(new Case(1, 'M', Case.BLANC));
            grid.Add(new Case(2, 'M', Case.BLANC));
            grid.Add(new Case(3, 'M', Case.ROSE));
            grid.Add(new Case(4, 'M', Case.BLANC));
            grid.Add(new Case(5, 'M', Case.BLANC));
            grid.Add(new Case(6, 'M', Case.BLANC));
            grid.Add(new Case(7, 'M', Case.BLEU_CLAIR));
            grid.Add(new Case(8, 'M', Case.BLANC));
            grid.Add(new Case(9, 'M', Case.BLEU_CLAIR));
            grid.Add(new Case(10, 'M', Case.BLANC));
            grid.Add(new Case(11, 'M', Case.BLANC));
            grid.Add(new Case(12, 'M', Case.BLANC));
            grid.Add(new Case(13, 'M', Case.ROSE));
            grid.Add(new Case(14, 'M', Case.BLANC));
            grid.Add(new Case(15, 'M', Case.BLANC));

            grid.Add(new Case(1, 'N', Case.BLANC));
            grid.Add(new Case(2, 'N', Case.ROSE));
            grid.Add(new Case(3, 'N', Case.BLANC));
            grid.Add(new Case(4, 'N', Case.BLANC));
            grid.Add(new Case(5, 'N', Case.BLANC));
            grid.Add(new Case(6, 'N', Case.BLEU_FONCE));
            grid.Add(new Case(7, 'N', Case.BLANC));
            grid.Add(new Case(8, 'N', Case.BLANC));
            grid.Add(new Case(9, 'N', Case.BLANC));
            grid.Add(new Case(10, 'N', Case.BLEU_FONCE));
            grid.Add(new Case(11, 'N', Case.BLANC));
            grid.Add(new Case(12, 'N', Case.BLANC));
            grid.Add(new Case(13, 'N', Case.BLANC));
            grid.Add(new Case(14, 'N', Case.ROSE));
            grid.Add(new Case(15, 'N', Case.BLANC));

            grid.Add(new Case(1, 'O', Case.ROUGE));
            grid.Add(new Case(2, 'O', Case.BLANC));
            grid.Add(new Case(3, 'O', Case.BLANC));
            grid.Add(new Case(4, 'O', Case.BLEU_CLAIR));
            grid.Add(new Case(5, 'O', Case.BLANC));
            grid.Add(new Case(6, 'O', Case.BLANC));
            grid.Add(new Case(7, 'O', Case.BLANC));
            grid.Add(new Case(8, 'O', Case.ROUGE));
            grid.Add(new Case(9, 'O', Case.BLANC));
            grid.Add(new Case(10, 'O', Case.BLANC));
            grid.Add(new Case(11, 'O', Case.BLANC));
            grid.Add(new Case(12, 'O', Case.BLEU_CLAIR));
            grid.Add(new Case(13, 'O', Case.BLANC));
            grid.Add(new Case(14, 'O', Case.BLANC));
            grid.Add(new Case(15, 'O', Case.ROUGE));
        }

        public Case getCase(int x, char y){
            foreach(Case c in grid){
                if (x == c.getX() && y == c.getY())
                    return c;
            }

            throw new Exception("Case non trouvée");
        }

        public Case getCase(int x, int y)
        {
            char[] header_y = { ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O' };

            foreach (Case c in grid)
            {
                if (x == c.getX() && header_y[y] == c.getY())
                    return c;
            }

            throw new Exception("Case non trouvée");
        }

        private void FillCase(Letter Letter, Case targetedCase)
        {
             targetedCase.setLetter(Letter);
        }
    }
}
